import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:leader_doctor_flutter/styles/colors.dart';

class CustomAlertDialog extends StatelessWidget {
  final String title;
  final String description;
  final VoidCallback? onConfirm;
  final VoidCallback? onCancel;
  final Widget? cancelText;
  final Widget? confirmText;

  const CustomAlertDialog({
    super.key,
    required this.title,
    required this.description,
    this.onConfirm,
    this.onCancel,
    this.cancelText,
    this.confirmText,
  });

  @override
  Widget build(BuildContext context) {
    double dialogWidth = MediaQuery.of(context).size.width / 2;

    return AlertDialog(
      title: Center(
        child: Text(
          title,
          style: TextStyle(fontSize: 18, color: Color(0xFF000000)),
        ),
      ),
      contentPadding: EdgeInsets.zero,
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          SizedBox(height: 10),
          Container(
            padding: EdgeInsets.only(left: 10.w, right: 10.w),
            alignment: Alignment.center,
            child: Text(
              description,
              style: TextStyle(color: Color(0xFF666666)),
            ),
          ),
          SizedBox(height: 20), // 间距调整，可根据需要修改
          Divider(height: 1, color: Color(0xFFCCCCCC)), // 分割线
          SizedBox(height: 0), // 间距调整，可根据需要修改
          IntrinsicHeight(
            child: Row(
              children: [
                Expanded(
                  child: TextButton(
                    onPressed: () async {
                      onCancel?.call();
                      Navigator.pop(context, 'onCancel');
                    },
                    style: ButtonStyle(
                      overlayColor: MaterialStateProperty.resolveWith((states) {
                        return Colors.transparent;
                      }),
                    ),
                    child: cancelText ?? buildCancelText(),
                  ),
                ),
                SizedBox(
                  width: 0.5,
                  child: Container(
                    color: Color(0xFFCCCCCC),
                  ),
                ),
                Expanded(
                  child: TextButton(
                    onPressed: () async {
                      onConfirm?.call();
                      Navigator.pop(context, 'onConfirm');
                    },
                    style: ButtonStyle(
                      backgroundColor:
                      MaterialStateProperty.resolveWith((states) {
                        return Colors.transparent;
                      }),
                      overlayColor: MaterialStateProperty.resolveWith((states) {
                        return Colors.transparent;
                      }),
                    ),
                    child: confirmText ?? buildConfirm(),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Text buildConfirm() {
    return const Text(
      '确定',
      style: TextStyle(color: ColorRes.colorMain, fontSize: 16),
    );
  }

  Text buildCancelText() {
    return const Text(
      '取消',
      style: TextStyle(color: Color(0xFF333333), fontSize: 16),
    );
  }
}
